import uuid
from datetime import datetime
from typing import Optional, List

from pydantic import BaseModel
from app.schemas.base import BaseSchema


class UploadedFileBase(BaseModel):
    filename: str
    content_type: str
    file_size: int
    file_type: int


class UploadedFileCreate(UploadedFileBase):
    user_id: Optional[uuid.UUID] = None
    file_path: str
    parsed_content: Optional[str] = None


class UploadedFileInDB(BaseSchema):
    id: uuid.UUID
    user_id: Optional[uuid.UUID] = None
    filename: str
    content_type: str
    file_size: int
    file_type: int
    file_path: str
    parsed_content: Optional[str] = None
    created_at: datetime

    model_config = {"from_attributes": True}


class UploadedFileResponse(BaseModel):
    file_id: uuid.UUID
    filename: str
    file_type: int
    file_path: str
    file_size: int
    content: Optional[str] = None


class FileCountResponse(BaseModel):
    """Response for file count endpoint"""
    count: int


class MedicalReportExtraction(BaseModel):
    """AI提取的医疗报告结构化数据"""
    disease_name: Optional[str] = None
    report_category: Optional[str] = None
    report_name: Optional[str] = None
    report_date: Optional[str] = None  # 从AI返回的日期字符串
    hospital_name: Optional[str] = None


class FileListItem(BaseSchema):
    """文件列表项"""
    file_id: uuid.UUID
    filename: str
    content_type: str
    file_size: int
    file_type: int
    created_at: datetime


class FileListResponse(BaseModel):
    """文件列表分页响应"""
    items: List[FileListItem]
    total: int
    page: int
    page_size: int
    total_pages: int


class BatchUploadResponse(BaseModel):
    """批量上传响应"""
    uploaded_files: List[UploadedFileResponse]
    total_count: int
    success_count: int
    failed_count: int
    failed_files: List[str] = []  # 失败的文件名列表
